package cn.net.zidian.mvvm.activity;

import android.view.LayoutInflater;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import cn.net.zidian.bean.HistoryBean;
import cn.net.zidian.databinding.ActivityAstroBinding;
import cn.net.zidian.databinding.ActivityAstroDetailsBinding;
import cn.net.zidian.mvvm.adapter.AstroAdapter;
import cn.net.zidian.mvvm.adapter.AstroDetailsAdapter;
import cn.net.zidian.mvvm.vm.AstroDetailsVM;
import cn.net.zidian.mvvm.vm.AstroVM;
import cn.net.zidian.util.HistoryData;

public class AstroDetailsActivity extends BaseActivity<AstroDetailsVM> {

    private ActivityAstroDetailsBinding viewBinding;

    private AstroDetailsAdapter adapter = new AstroDetailsAdapter();

    @Override
    protected AstroDetailsVM viewModel() {
        return new AstroDetailsVM();
    }

    @Override
    protected void initView() {
        initObserver();
        viewBinding = ActivityAstroDetailsBinding.inflate(LayoutInflater.from(this));
        setContentView(viewBinding.getRoot());
        viewBinding.titleBar.setTitle(getIntent().getStringExtra("name"));
        HistoryData.list.add(new HistoryBean(getIntent().getStringExtra("name"), "星座"));
        viewBinding.titleBar.getLeftView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        viewBinding.rvList.setLayoutManager(new LinearLayoutManager(this));
        viewBinding.rvList.setAdapter(adapter);
        vm.getList(getIntent().getStringExtra("id"));
    }
    public void initObserver() {
        vm.eventList.observe(this, list -> adapter.setNewData(list));
    }

}
